﻿define(function (require, exports, module) {
    return function (jQuery) {
        (function ($) {
            /*seajs-content-start*/
            var dateFormat = function (date, fmt) { //author: meizz
                var o = {
                    "M+": date.getMonth() + 1,                 //月份
                    "d+": date.getDate(),                    //日
                    "h+": date.getHours(),                   //小时
                    "m+": date.getMinutes(),                 //分
                    "s+": date.getSeconds(),                 //秒
                    "q+": Math.floor((date.getMonth() + 3) / 3), //季度
                    "S": date.getMilliseconds()             //毫秒
                };
                if (/(y+)/.test(fmt))
                    fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
                for (var k in o)
                    if (new RegExp("(" + k + ")").test(fmt))
                        fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
                return fmt;
            };

            var checkCellIndicatorCtrl = function ($scope, httpservice) {

                /*设置title和初始化未查询页面*/
                $scope.$emit('title', '小区Q值指标分析');
                $scope.visible = true;
                $scope.starttime = "";
                $scope.endtime = "";
                $scope.timesize = "hour";

                $scope.visible2 = true;
                $scope.starttime2 = "";
                $scope.endtime2 = "";
                $scope.timesize2 = "hour";

                $scope.starttime = dateFormat(new Date(),"yyyy-MM-dd 00:00:00");
                $scope.endtime = dateFormat(new Date(),"yyyy-MM-dd 23:00:00") ;
                $scope.starttime2 = dateFormat(new Date(),"yyyy-MM-dd 00:00:00");
                $scope.endtime2 = dateFormat(new Date(),"yyyy-MM-dd 23:00:00") ;

                $scope.servicetype = "视频";
                $scope.servicetype2 = "视频";

                $scope.pageSize = 15;


                var downloadoperate = function(cellvalue, options, rowObject){
                    var listprint = "<a class='viewmodel' href='javascript:'id='"+rowObject.id+"' title = '查看'><img src='../../../images/chakan.png' /></a>" +
                        "<a class='downloadmodel' style='margin: 0 15px;' href= '"+httpservice.downloadurl+""+rowObject.filename+".csv' target='_blank' id='"+rowObject.id+"' state='"+rowObject.status+"' title='下载'><img src='../../../images/download.png' /></a>" +
                        "<a class='deletemodel' href='javascript:' id='"+rowObject.id+"' state='"+rowObject.state+"' title='删除'><img src='../../../images/delete1.png' /></a>";
                    return listprint;
                };

                //提交下载任务
                var submitDownloadTask = function (postdata,posturl) {
                    $.ajax({
                        url: posturl,
                        type: "POST",
                        data: JSON.stringify(postdata),
                        dataType: "json",
                        success: function (result, textStatus) {
                            if(result.state){
                                alert('提交下载任务成功!');
                            }
                            else{
                                alert("提交下载任务失败,\r\n"+result.error);
                            }
                        },
                        error:function(xmlHttpRequest,textStatus){
                            alert("请求出错!");
                        },
                        complete:function(xmlHttpRequest,textStatus){

                        }
                    });
                };

                //时间粒度选择
                $("#selecttimesize").live("change",function(){
                    var timesize = $(this).val();
                    switch(timesize){
                        case "hour":
                            //初始化時間
                            $scope.starttime = dateFormat(new Date(),"yyyy-MM-dd 00:00:00");
                            $scope.endtime = dateFormat(new Date(),"yyyy-MM-dd 01:00:00") ;

                            $("#starttime").attr("onfocus", "WdatePicker({skin:'twoer',dateFmt:'yyyy-MM-dd HH:00:00'})");
                            $("#endtime").attr("onfocus", "WdatePicker({skin:'twoer',dateFmt:'yyyy-MM-dd HH:00:00'})");

                            $scope.visible = true;
                            $scope.timesize = timesize;
                            break;
                        case "day":
                            //初始化時間
                            $scope.starttime = dateFormat(new Date(),"yyyy-MM-dd");
                            $scope.endtime = dateFormat(new Date(),"yyyy-MM-dd") ;

                            $("#starttime").attr("onfocus", "WdatePicker({skin:'twoer',dateFmt:'yyyy-MM-dd'})");
                            $("#endtime").attr("onfocus", "WdatePicker({skin:'twoer',dateFmt:'yyyy-MM-dd'})");

                            $scope.visible = true;
                            $scope.timesize = timesize;
                            break;
                        case "month":
                            $("#starttime").attr("onfocus", "WdatePicker({skin:'twoer',dateFmt:'yyyy-MM'})");

                            $scope.visible = false;
                            $scope.starttime = dateFormat(new Date(),"yyyy-MM");
                            $scope.endtime = dateFormat(new Date(),"yyyy-MM");
                            $scope.timesize = timesize;
                            break;
                    }
                    $scope.$apply();
                });

                $("#selecttimesize2").live("change",function(){
                    var timesize = $(this).val();
                    switch(timesize){
                        case "hour":
                            //初始化時間
                            $scope.starttime2 = dateFormat(new Date(),"yyyy-MM-dd 00:00:00");
                            $scope.endtime2 = dateFormat(new Date(),"yyyy-MM-dd 23:00:00") ;

                            $("#starttime2").attr("onfocus", "WdatePicker({skin:'twoer',dateFmt:'yyyy-MM-dd HH:00:00'})");
                            $("#endtime2").attr("onfocus", "WdatePicker({skin:'twoer',dateFmt:'yyyy-MM-dd HH:00:00'})");

                            $scope.visible2 = true;
                            $scope.timesize2 = timesize;
                            break;
                        case "day":
                            //初始化時間
                            $scope.starttime2 = dateFormat(new Date(),"yyyy-MM-dd");
                            $scope.endtime2 = dateFormat(new Date(),"yyyy-MM-dd") ;

                            $("#starttime2").attr("onfocus", "WdatePicker({skin:'twoer',dateFmt:'yyyy-MM-dd'})");
                            $("#endtime2").attr("onfocus", "WdatePicker({skin:'twoer',dateFmt:'yyyy-MM-dd'})");

                            $scope.visible2 = true;
                            $scope.timesize2 = timesize;
                            break;
                        case "month":
                            $("#starttime2").attr("onfocus", "WdatePicker({skin:'twoer',dateFmt:'yyyy-MM'})");

                            $scope.visible2 = false;
                            $scope.starttime2 = dateFormat(new Date(),"yyyy-MM");
                            $scope.endtime2 = dateFormat(new Date(),"yyyy-MM");
                            $scope.timesize2 = timesize;
                            break;
                    }
                    $scope.$apply();
                });

                //业务类型选择
                $("#servicetype").live("change",function(){
                    var servicetype = $(this).val();
                    $scope.servicetype = servicetype;
                })

                $("#servicetype2").live("change",function(){
                    var servicetype = $(this).val();
                    $scope.servicetype2 = servicetype;
                })

                var formatValue = function(cellvalue, options, rowObject){
                    var startDateTime = new Date(rowObject.dateTime);
                    var endDateTime = dateFormat(new Date(rowObject.dateTime), 'yyyy-MM-dd hh:00:00');
                    //alert(new Date(startDateTime.setHours(startDateTime.getHours() + 1)));
                    switch($scope.timesize){
                        case "hour":
                            endDateTime = dateFormat(new Date(startDateTime.setHours(startDateTime.getHours() + 1)),'yyyy-MM-dd hh:00:00');
                            break;
                        case "day":
                            endDateTime = dateFormat(new Date(startDateTime.setDate(startDateTime.getDate() + 1)),'yyyy-MM-dd');
                            break;
                        case "month":
                            //endDateTime = dateFormat(new Date(startDateTime.setMonth(startDateTime.getMonth() + 1)),'yyyy-MM');
                            break;
                    }
                    var stylevalue = "font-size:14px;font-weight:bold;cursor: pointer;text-decoration: underline;";
                    var listprint = "<span class='drill' startDateTime='"+rowObject.dateTime+"' endDateTime='"+endDateTime+"' lacCi='"+rowObject.lacCi+"' title='点击下钻' style='"+stylevalue+"'>"+cellvalue+"</span>";
                    return listprint;
                }

                //点击下钻
                $(".drill").live("click",function(e){
                    //alert($(this).attr("servicetype"));
                    $scope.lacci = $(this).attr("lacCi");
                    var condition = {
                        pageindex:1,
                        pagesize:$scope.pageSize,
                        timesize:$("#selecttimesize").val(),
                        starttime:$(this).attr("startDateTime"),
                        endtime:$(this).attr("endDateTime"),
                        dimensionvalue:$(this).attr("lacCi"),
                        servicetype:$("#servicetype").val()
                    }
                    $scope.tabs1.obj.tabs('select', 1);
                    $("#selecttimesize2").val(condition.timesize);
                    $("#starttime2").val(condition.starttime);
                    $("#servicetype2").val(condition.servicetype);
                    $("#endtime2").val(condition.endtime);
                    timesize = $scope.timesize;
                    switch(timesize){
                        case "hour":
                            $("#starttime2").attr("onfocus", "WdatePicker({skin:'twoer',dateFmt:'yyyy-MM-dd HH:00'})");
                            $("#endtime2").attr("onfocus", "WdatePicker({skin:'twoer',dateFmt:'yyyy-MM-dd HH:00'})");
                            break;
                        case "day":
                            $("#starttime2").attr("onfocus", "WdatePicker({skin:'twoer',dateFmt:'yyyy-MM-dd'})");
                            $("#endtime2").attr("onfocus", "WdatePicker({skin:'twoer',dateFmt:'yyyy-MM-dd'})");
                            break;
                        case "month":
                            $("#starttime2").attr("onfocus", "WdatePicker({skin:'twoer',dateFmt:'yyyy-MM'})");
                            $("#endtime2").attr("onfocus", "WdatePicker({skin:'twoer',dateFmt:'yyyy-MM'})");
                            $scope.visible2 = false;
                            break;
                    }
                    flushPage(condition, "f2");
                })

                $scope.tabs1 = {
                    obj:''
                };

                $scope.indicatorgrid = {
                    gridpagedata:{
                        nowpage:1,
                        totalpage:20,
                        totalcount:20,
                        startline:1,
                        endline:20,
                        pagesize:$scope.pageSize,
                        pagelist:[10,15,20,50,100],
                        datacount:20,
                        toFirstpage: function(){
                            //alert('首页');
                            $scope.indicatorgrid.gridpagedata.nowpage = 1;
                            var condition ={
                                pageindex:$scope.indicatorgrid.gridpagedata.nowpage,
                                pagesize:$scope.indicatorgrid.gridpagedata.pagesize,
                                timesize:$("#selecttimesize").val(),
                                starttime:$("#starttime").val(),
                                endtime:$("#endtime").val(),
                                servicetype:$("#servicetype").val()
                            }
                            flushPage(condition, "f1");
                        },
                        toToppage: function(){
                            //alert('上一页');
                            if ($scope.indicatorgrid.gridpagedata.nowpage > 1) {
                                $scope.indicatorgrid.gridpagedata.nowpage--;
                                var condition ={
                                    pageindex:$scope.indicatorgrid.gridpagedata.nowpage,
                                    pagesize:$scope.indicatorgrid.gridpagedata.pagesize,
                                    timesize:$("#selecttimesize").val(),
                                    starttime:$("#starttime").val(),
                                    endtime:$("#endtime").val(),
                                    servicetype:$("#servicetype").val()
                                }
                                flushPage(condition, "f1");
                            }
                        },
                        toNextpage: function(){
                            //alert('下一页');
                            if ($scope.indicatorgrid.gridpagedata.nowpage < $scope.indicatorgrid.gridpagedata.totalpage) {
                                $scope.indicatorgrid.gridpagedata.nowpage++;
                                var condition ={
                                    pageindex:$scope.indicatorgrid.gridpagedata.nowpage,
                                    pagesize:$scope.indicatorgrid.gridpagedata.pagesize,
                                    timesize:$("#selecttimesize").val(),
                                    starttime:$("#starttime").val(),
                                    endtime:$("#endtime").val(),
                                    servicetype:$("#servicetype").val()
                                }
                                flushPage(condition, "f1");
                            }
                        },
                        toLastpage: function(){
                            //alert('最后一页');
                            $scope.indicatorgrid.gridpagedata.nowpage = $scope.indicatorgrid.gridpagedata.totalpage;
                            var condition ={
                                pageindex:$scope.indicatorgrid.gridpagedata.nowpage,
                                pagesize:$scope.indicatorgrid.gridpagedata.pagesize,
                                timesize:$("#selecttimesize").val(),
                                starttime:$("#starttime").val(),
                                endtime:$("#endtime").val(),
                                servicetype:$("#servicetype").val()
                            }
                            flushPage(condition, "f1");
                        },
                        topage: function(){
                            //alert('第' + $scope.grid1.gridpagedata.nowpage + '页');
                            var condition ={
                                pageindex:$scope.indicatorgrid.gridpagedata.nowpage,
                                pagesize:$scope.indicatorgrid.gridpagedata.pagesize,
                                timesize:$("#selecttimesize2").val(),
                                starttime:$("#starttime2").val(),
                                endtime:$("#endtime2").val(),
                                servicetype:$("#servicetype2").val()
                            }
                            flushPage(condition, "f1");
                        },
                        changePagesize: function(){
                            //alert('切换到每页' + $scope.grid1.gridpagedata.pagesize + '条');
                            $scope.indicatorgrid.gridpagedata.nowpage = 1;
                            var condition ={
                                pageindex:$scope.indicatorgrid.gridpagedata.nowpage,
                                pagesize:$scope.indicatorgrid.gridpagedata.pagesize,
                                timesize:$("#selecttimesize").val(),
                                starttime:$("#starttime").val(),
                                endtime:$("#endtime").val(),
                                servicetype:$("#servicetype").val()
                            }
                            flushPage(condition, "f1");
                        }
                    },
                    griddata: {
                        colnames: [ "时间",'小区号','平均tcp下行时延(ms)','流量(MB)','下载速率(kbps)','Q值'],
                        colmodel: [
                            { name: 'dateTime', index: 'dateTime', width: 220, sortable: true, align:"center"},
                            { name: 'lacCi', index: 'lacCi', width: 220, sortable: true,align:"center" },
                            { name: 'tcpDelay', index: 'tcpDelay', width: 220, sortable: true, align:"center"},
                            { name: 'ipLen', index: 'ipLen', width: 220, sortable: true, align:"center"},
                            { name: 'dlRate', index: 'dlRate', width: 220, sortable: true, align:"center"},
                            { name: 'qValue', index: 'qValue', width: 220, sortable: true, align:"center",formatter:formatValue}
                        ],
                        data: [
                            //{ "dateTime": "2016-10-08 20:00:00", "lacCi": "1234_5678", "tcpDelay":"95", "ipLen":"10240", "dlRate":"20", "qValue":"10"},
                            //{ "dateTime": "2016-10-08 21:00:00", "lacCi": "14335_5676", "tcpDelay":"90", "ipLen":"10490", "dlRate":"20", "qValue":"10"}
                        ]
                    },
                    obj:{},
                    shrinkToFit:true,
                    gridresize: function (grid) {
                        grid.setGridWidth(parseInt($(window).width()-24));
                        grid.setGridHeight(parseInt(($(window).height()-255)));
                    }
                };

                $scope.indicatorgrid2 = {
                    gridpagedata:{
                        nowpage:1,
                        totalpage:20,
                        totalcount:20,
                        startline:1,
                        endline:20,
                        pagesize:$scope.pageSize,
                        pagelist:[10,15,20,50,100],
                        datacount:20,
                        toFirstpage: function(){
                            //alert('首页');
                            $scope.indicatorgrid2.gridpagedata.nowpage = 1;
                            var condition ={
                                pageindex:$scope.indicatorgrid2.gridpagedata.nowpage,
                                pagesize:$scope.indicatorgrid2.gridpagedata.pagesize,
                                timesize:$("#selecttimesize2").val(),
                                starttime:$("#starttime2").val(),
                                endtime:$("#endtime2").val(),
                                dimensionvalue:$scope.lacci,
                                servicetype:$("#servicetype2").val()
                            }
                            flushPage(condition, "f2");
                        },
                        toToppage: function(){
                            //alert('上一页');
                            if ($scope.indicatorgrid2.gridpagedata.nowpage > 1) {
                                $scope.indicatorgrid2.gridpagedata.nowpage--;
                                var condition ={
                                    pageindex:$scope.indicatorgrid2.gridpagedata.nowpage,
                                    pagesize:$scope.indicatorgrid2.gridpagedata.pagesize,
                                    timesize:$("#selecttimesize2").val(),
                                    starttime:$("#starttime2").val(),
                                    endtime:$("#endtime2").val(),
                                    dimensionvalue:$scope.lacci,
                                    servicetype:$("#servicetype2").val()
                                }
                                flushPage(condition, "f2");
                            }
                        },
                        toNextpage: function(){
                            //alert('下一页');
                            if ($scope.indicatorgrid2.gridpagedata.nowpage < $scope.indicatorgrid2.gridpagedata.totalpage) {
                                $scope.indicatorgrid2.gridpagedata.nowpage++;
                                var condition ={
                                    pageindex:$scope.indicatorgrid2.gridpagedata.nowpage,
                                    pagesize:$scope.indicatorgrid2.gridpagedata.pagesize,
                                    timesize:$("#selecttimesize2").val(),
                                    starttime:$("#starttime2").val(),
                                    endtime:$("#endtime2").val(),
                                    dimensionvalue:$scope.lacci,
                                    servicetype:$("#servicetype2").val()
                                }
                                flushPage(condition, "f2");
                            }
                        },
                        toLastpage: function(){
                            //alert('最后一页');
                            $scope.indicatorgrid2.gridpagedata.nowpage = $scope.indicatorgrid2.gridpagedata.totalpage;
                            var condition ={
                                pageindex:$scope.indicatorgrid2.gridpagedata.nowpage,
                                pagesize:$scope.indicatorgrid2.gridpagedata.pagesize,
                                timesize:$("#selecttimesize2").val(),
                                starttime:$("#starttime2").val(),
                                endtime:$("#endtime2").val(),
                                dimensionvalue:$scope.lacci,
                                servicetype:$("#servicetype2").val()
                            }
                            flushPage(condition, "f2");
                        },
                        topage: function(){
                            //alert('第' + $scope.grid1.gridpagedata.nowpage + '页');
                            var condition ={
                                pageindex:$scope.indicatorgrid2.gridpagedata.nowpage,
                                pagesize:$scope.indicatorgrid2.gridpagedata.pagesize,
                                timesize:$("#selecttimesize2").val(),
                                starttime:$("#starttime2").val(),
                                endtime:$("#endtime2").val(),
                                dimensionvalue:$scope.lacci,
                                servicetype:$("#servicetype2").val()
                            }
                            flushPage(condition, "f2");
                        },
                        changePagesize: function(){
                            //alert('切换到每页' + $scope.grid1.gridpagedata.pagesize + '条');
                            $scope.indicatorgrid2.gridpagedata.nowpage = 1;
                            var condition ={
                                pageindex:$scope.indicatorgrid2.gridpagedata.nowpage,
                                pagesize:$scope.indicatorgrid2.gridpagedata.pagesize,
                                timesize:$("#selecttimesize2").val(),
                                starttime:$("#starttime2").val(),
                                endtime:$("#endtime2").val(),
                                dimensionvalue:$scope.lacci,
                                servicetype:$("#servicetype2").val()
                            }
                            flushPage(condition, "f2");
                        }
                    },
                    griddata: {
                        colnames: [ "时间",'小区号','业务名称','流量(MB)','速率(kbps)'],
                        colmodel: [
                            { name: 'dateTime', index: 'dateTime', width: 220, sortable: true, align:"center"},
                            { name: 'lacCi', index: 'lacCi', width: 220, sortable: true,align:"center" },
                            { name: 'serviceName', index: 'tcpDelay', width: 220, sortable: true, align:"center"},
                            { name: 'ipLen', index: 'ipLen', width: 220, sortable: true, align:"center"},
                            { name: 'dlRate', index: 'dlRate', width: 220, sortable: true, align:"center"},
                        ],
                        data: [
                            //{ "dateTime": "2016-10-08 20:00:00", "lacCi": "1234_5678", "serviceName":"95", "ipLen":"10240", "dlRate":"20"},
                            //{ "dateTime": "2016-10-08 21:00:00", "lacCi": "14335_5676", "serviceName":"90", "ipLen":"10490", "dlRate":"20"}
                        ]
                    },
                    obj:{},
                    shrinkToFit:true,
                    gridresize: function (grid) {
                        grid.setGridWidth(parseInt($(window).width()-24));
                        grid.setGridHeight(parseInt(($(window).height()-255)));
                    }
                };

                //查询小区Q值指标分析
                $scope.query = function(){
                    if($("#starttime").val() == ""){
                        alert("请选择开始时间");
                        return false;
                    }
                    if($("#endtime").val() == ""){
                        alert("请选择结束时间");
                        return false;
                    }
                    $scope.indicatorgrid.gridpagedata.nowpage = 1;
                    var condition ={
                        pageindex:$scope.indicatorgrid.gridpagedata.nowpage,
                        pagesize:$scope.indicatorgrid.gridpagedata.pagesize,
                        starttime:$("#starttime").val(),
                        endtime:$("#endtime").val(),
                        timesize:$scope.timesize,
                        servicetype:$scope.servicetype
                    }
                    flushPage(condition, "f1");
                }

                //查询小区Q值指标详细
                $scope.query2 = function(){
                    if($("#starttime2").val() == ""){
                        alert("请选择开始时间");
                        return false;
                    }
                    if($("#endtime2").val() == ""){
                        alert("请选择结束时间");
                        return false;
                    }
                    $scope.lacci = "";
                    $scope.indicatorgrid2.gridpagedata.nowpage = 1;
                    var condition ={
                        pageindex:$scope.indicatorgrid2.gridpagedata.nowpage,
                        pagesize:$scope.pageSize,
                        starttime:$("#starttime2").val(),
                        endtime:$("#endtime2").val(),
                        timesize:$scope.timesize2,
                        dimensionvalue:$scope.lacci,
                        servicetype:$scope.servicetype2
                    }

                    flushPage(condition, "f2");
                }

                var flushPage = function(condition,fun){
                    $scope.$emit('loading', 'true');
                    $scope.$apply();
                    if (fun == "f1")
                    {
                        var f1 = $scope.getCheckCellIndicators(condition);
                    }
                    else if (fun == "f2")
                    {
                        var f2 = $scope.getCheckCellIndicatorsDetail(condition);
                    }

                    $.when(f1,f2).then(function(){

                    }).always(function() {
                            $scope.$emit('loading', 'false');
                            $scope.$apply();
                    });
                }

                //获取互联网四项考核指标Q值指标分析
                $scope.getCheckCellIndicators = function(condition){
                    return httpservice.post("script/CheckCell/GetQValueIndicators",JSON.stringify(condition),function(result){
                        $scope.indicatorgrid.gridpagedata.totalcount = result.recordCount;
                        $scope.indicatorgrid.gridpagedata.totalpage = result.pageCount;
                        $scope.indicatorgrid.gridpagedata.startline = result.startLine;
                        $scope.indicatorgrid.gridpagedata.endline = result.endLine;
                        $scope.indicatorgrid.gridpagedata.datacount = result.dataCount;
                        $scope.indicatorgrid.griddata.data = result.datas;
                        $scope.$apply();
                    });
                }

                $scope.getCheckCellIndicatorsDetail = function(condition){
                    return httpservice.post("script/CheckCell/GetCellCheckIndicatorsDetail",JSON.stringify(condition),function(result){
                        $scope.indicatorgrid2.gridpagedata.totalcount = result.recordCount;
                        $scope.indicatorgrid2.gridpagedata.totalpage = result.pageCount;
                        $scope.indicatorgrid2.gridpagedata.startline = result.startLine;
                        $scope.indicatorgrid2.gridpagedata.endline = result.endLine;
                        $scope.indicatorgrid2.gridpagedata.datacount = result.dataCount;
                        $scope.indicatorgrid2.griddata.data = result.datas;
                        $scope.$apply();
                    });
                }

                $scope.dialogList={
                    title:"下载列表",
                    ok:function(){},
                    cancel:function(){}
                }

                $scope.downloadList = {
                    griddata: {
                        colnames: ['ID','下载文件名', '创建时间','主模块','子模块','应用名称', '下载状态', '操作'],
                        colmodel: [
                            { name: 'id', index: 'id', sortable: false, align:"center",hidden:true },
                            { name: 'filename', index: 'filename', sortable: false, align:"center" },
                            { name: 'createtime', index: 'createtime', sortable: false, align:"center" },
                            { name: 'mainmodule', index: 'mainmodule', sortable: false, align:"center"},
                            { name: 'submodule', index: 'submodule', sortable: false, align:"center"},
                            { name: 'appname', index: 'appname', sortable: false,sorttype: 'number', align:"center"},
                            { name: 'status', index: 'status', sortable: false,sorttype: 'number', align:"center"},
                            { name: 'operate', index: 'operate', sortable: false, align:"center",formatter:downloadoperate}
                        ],
                        data: [
                            { "filename": "微信", "mainmodule": 1000, "submodule":1000, "appname":1000, "createtime": 1000,"status":1000, "operate":1000}
                        ]
                    },
                    obj:{},
                    shrinkToFit:true,
                    gridresize: function (grid) {
                        grid.setGridWidth(800);
                        grid.setGridHeight(300);
                    }
                };

                $scope.showDownloadlist = function(){
                    $scope.dialogList.show();
                    $scope.getCheckDownloadList();
                }

                $scope.getDownloadList = function(postdata){
                    $.ajax({
                        url:httpservice.serverurl + "script/Common/GetTaskList",
                        type:"post",
                        data:JSON.stringify(postdata),
                        dataType:"json",
                        success:function(result){
                            $scope.downloadList.griddata.data = result.datas;
                            $scope.$apply();
                        },
                        error:function(xmlHttpRequest,textStatus){
                            //alert("请求出错!");
                        },
                        complete:function(xmlhHttpRequest,textStatus){

                        }
                    });
                }

                $scope.getCheckDownloadList = function(){
                    var condition = {
                        mainmodule:"网络指标监控",
                        submodule:"小区Q值分析"
                    }
                    $scope.getDownloadList(condition);
                }

                //小区Q值分析
                $scope.submitQValueTask = function(size){
                    var isData = true;
                    isData = ($scope.indicatorgrid.griddata.data.length>0);

                    if(!isData){
                        alert('无数据导出，请先查询!');
                        return false;
                    }
                    var condition ={
                        starttime:$("#starttime").val(),
                        endtime:$("#endtime").val(),
                        timesize:$scope.timesize,
                        servicetype:$scope.servicetype,
                        mainmodule:"网络指标监控",
                        submodule:"小区Q值分析",
                        appname:'小区Q值分析'
                    }
                    var url = httpservice.serverurl + "script/CheckCell/SubmitCellQvalueTask";
                    submitDownloadTask(condition,url);
                }

                //小区Q值详细
                $scope.submitQValueDetailTask = function(size){
                    var isData = true;
                    isData = ($scope.indicatorgrid2.griddata.data.length>0);

                    if(!isData){
                        alert('无数据导出，请先查询!');
                        return false;
                    }
                    var condition ={
                        starttime:$("#starttime2").val(),
                        endtime:$("#endtime2").val(),
                        timesize:$scope.timesize2,
                        servicetype:$scope.servicetype2,
                        dimensionvalue:$scope.lacci,
                        mainmodule:"网络指标监控",
                        submodule:"小区Q值分析",
                        appname:'小区Q值详细'
                    }
                    var url = httpservice.serverurl + "script/CheckCell/SubmitCellQvalueDetailTask";
                    submitDownloadTask(condition,url);
                }

                //删除下载文件
                $(".deletemodel").live("click",function(e){
                    var fileId = $(e.target).parent().attr("id");
                    if(confirm('你确定要删除该文件?')){
                        $.ajax({
                            url:httpservice.serverurl + "script/Common/DeleteTask",
                            type:"get",
                            data:{id:fileId},
                            dataType:"json",
                            success:function(result){
                                if(result.state){
                                    var condition = {
                                        mainmodule:"网络指标监控",
                                        submodule:"小区Q值分析"
                                    }
                                    $scope.getDownloadList(condition);
                                    alert('删除成功!');
                                }
                                else{
                                    alert('删除失败!');
                                }
                            },
                            error:function(xmlHttpRequest,textStatus){
                                alert('请求出错!');
                            },
                            complete:function(xmlHttpRequest,textStatus){

                            }
                        });
                    }
                })

                var init = function () {
                    $scope.starttime = dateFormat(new Date(),"yyyy-MM-dd 00:00:00");
                    $scope.endtime = dateFormat(new Date(),"yyyy-MM-dd 23:00:00") ;
                    $scope.starttime2 = dateFormat(new Date(),"yyyy-MM-dd 00:00:00");
                    $scope.endtime2 = dateFormat(new Date(),"yyyy-MM-dd 23:00:00") ;

                    $scope.getCheckDownloadList();
                    setInterval(function(){
                        $scope.$apply($scope.getCheckDownloadList);
                    }, 60*1000);
                };
                init();
            };
            angular.module('checkCellIndicator-ctrl', [])
                .controller('CheckCellIndicatorCtrl', ['$scope', 'HttpService', checkCellIndicatorCtrl]);
            require('WdatePicker');
        })(jQuery);
    }
})
